package com.wsoft.form.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.form.query.operation.*;
import com.wsoft.form.service.IWfFormOperationService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * @Author z001
 * @Date 2024/8/30 14:47
 */
@RestController
@Tag(name = "表单操作")
@RequestMapping("/wf/op")
public class WfFormOperationController {

    @Resource
    private IWfFormOperationService operationService;

    @Operation(summary = "新增数据接口",description = "新增数据接口")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid OperationInsertQuery query) {
        operationService.addOperation(query);
        return ResponseResult.success("[sys.msg.success]");
    }

    @Operation(summary = "更新数据接口",description = "更新数据接口")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid OperationUpdateQuery query) {
        operationService.updateOperation(query);
        return ResponseResult.success("[sys.msg.success]");
    }

    @Operation(summary = "删除数据接口",description = "更新数据接口")
    @PostMapping("/delete")
    public ResponseResult delete(@RequestBody OperationDelQuery query) {
        operationService.delOperation(query.getDesignId(),query.getDataIdList());
        return ResponseResult.success("[sys.msg.success]");
    }

    @Operation(summary = "获取数据详情",description = "获取数据详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("designId") Long designId, @RequestParam("dataId") Long dataId) {
        Map<String, Object> map = operationService.getOperation(designId,dataId);
        return ResponseResult.success(map);
    }


    @Operation(summary = "查询数据接口",description = "查询数据接口")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody OperationListQuery query) {
        PageInfo<Map<String, Object>> list = operationService.listOperation(query);
        return ResponseResult.success(ResponsePage.restPage(list));
    }


    @Operation(summary = "查询数据关联接口",description = "查询数据关联接口")
    @PostMapping("/linkList")
    public ResponseResult linkList(@RequestBody LinkListQuery query) {
        PageInfo<Map<String, Object>> list = operationService.linkList(query);
        return ResponseResult.success(list);
    }

}
